package com.tenbent.product.center.user.bo;

import com.tenbent.product.base.bo.BizObject;
import com.tenbent.product.base.mybatis.annotations.TypeAlias;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

/**
 * 用户信息实体类
 *
 * @author Randy
 *
 *         Created by ThinkPad on 2017/8/31.
 */
@Entity
@Table(name = "pc_user")
@TypeAlias("user")
public class User extends BizObject {

	/** 登录ID */
	@Column(name = "login_id")
	private String loginId;

	/** 密码 */
	@Column
	private String password;

	/** 用户名称 */
	@Column
	private String name;

	public User() {

	}

	public User(String loginId, String password, String name) {
		PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
		this.loginId = loginId;
		this.password = passwordEncoder.encode(password);
		this.name = name;
	}

	public String getLoginId() {
		return loginId;
	}

	public void setLoginId(String loginId) {
		this.loginId = loginId;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;

		User user = (User) o;

		if (loginId != null ? !loginId.equals(user.loginId) : user.loginId != null)
			return false;
		if (password != null ? !password.equals(user.password) : user.password != null)
			return false;
		return name != null ? name.equals(user.name) : user.name == null;

	}

	@Override
	public int hashCode() {
		int result = loginId != null ? loginId.hashCode() : 0;
		result = 31 * result + (password != null ? password.hashCode() : 0);
		result = 31 * result + (name != null ? name.hashCode() : 0);
		return result;
	}

	@Override
	public String toString() {
		return "User{" + "loginId='" + loginId + '\'' + ", password='" + password + '\'' + ", name='" + name + '\''
				+ '}';
	}
}
